<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>高校健康上报系统登录</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">

    <!--[if lt IE 9]>
    <script src="/static/layui/html5.min.js"></script>
    <script src="/static/layui/respond.min.js"></script>
    <![endif]-->

    <style>
        body {background-image:url("images/bg.jpg");height:100%;width:100%;}
        #container{height:100%;width:100%;}
        input:-webkit-autofill {-webkit-box-shadow:inset 0 0 0 1000px #fff;background-color:transparent;}
        .admin-login-background {width:300px;height:300px;position:absolute;left:50%;top:40%;margin-left:-150px;margin-top:-100px;}
        .admin-header {text-align:center;margin-bottom:20px;color:#ffffff;font-weight:bold;font-size:40px}
        .admin-input {border-top-style:none;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;height:50px;width:300px;padding-bottom:0px;}
        .admin-input::-webkit-input-placeholder {color:#a78369}
        .layui-icon-username {color:#a78369 !important;}
        .layui-icon-username:hover {color:#9dadce !important;}
        .layui-icon-password {color:#a78369 !important;}
        .layui-icon-password:hover {color:#9dadce !important;}
        .admin-input-username {border-top-style:solid;border-radius:10px 10px 0 0;}
        .admin-input-verify {border-radius:0 0 10px 10px;}
        .admin-button {margin-top:20px;font-weight:bold;font-size:18px;width:300px;height:50px;border-radius:5px;background-color:#a78369;border:1px solid #d8b29f}
        .admin-icon {margin-left:260px;margin-top:10px;font-size:30px;}
        i {position:absolute;}
        .admin-captcha {position:absolute;margin-left:205px;margin-top:-40px;}
    </style>
</head>
<body>
<div id="container layui-anim layui-anim-upbit">
    <div></div>
    <div class="admin-login-background">
        <div class="admin-header">
            <span>高校健康上报系统登录</span>

        </div>
        <p th:text="${MESSAGE}"></p>
        <form class="layui-form" th:action="@{/login_end}" method="post" id="form1">
            <div>
                <i class="layui-icon layui-icon-username admin-icon"></i>
                <input type="text" name="username" id="username" placeholder="请输入用户名" class="layui-input admin-input admin-input-username" th:value="${username}">
            </div>
            <div>
                <i class="layui-icon layui-icon-password admin-icon"></i>
                <input type="password" name="password" id="password" placeholder="请输入密码" class="layui-input admin-input" th:value="${password}">
            </div>

            <br><a href="register-2.html">新用户？点击注册</a>
            <button class="layui-btn admin-button" lay-submit="login" lay-filter="login"
                    id="TencentCaptcha" data-appid="2038374610"
                    data-cbfn="callback"
                    type="button" data-biz-state="data-biz-state"
                    >登 陆</button>
        </form>
    </div>
</div>
<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="https://ssl.captcha.qq.com/TCaptcha.js"></script>
<script type="text/javascript" src="layui/jquery.min.js"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer;

        // 登录过期的时候，跳出ifram框架
        if (top.location !== self.location) top.location = self.location;

        // 进行登录操作
        form.on('submit(login)', function (data) {
            data = data.field;
            const data2 = data.field;
            if (data.username === '') {
                layer.msg('用户名不能为空');
                return false;
            }
            if (data.password === '') {
                layer.msg('密码不能为空');
                return false;
            }

            var captcha1 = new TencentCaptcha('2038374610', function(res) {
                if(res.ret === 0){
                    $.ajax({
                        url: "/checkLogin",
                        type: "POST",
                        data:{
                            "ticket":res.ticket,
                            "randstr":res.randstr
                        },
                        success: function (data) {
                            console.log("11"+data);
                            if (data.result ===0) {
                                $.ajax({
                                    url:"/login_end",
                                    type:"POST",
                                    data:{
                                        username:$('#username').val(),
                                        password:$('#password').val()
                                    },
                                    success: function(data){
                                        console.log("登录验证");
                                        console.log(data);
                                        if(data.state===true){
                                            if(data.admin===1){
                                                localStorage.setItem('token', data.token);
                                                window.location.href='/adminIndex';
                                            }else{
                                                localStorage.setItem('token', data.token);
                                                window.location.href='/userIndex';
                                            }
                                        }else{
                                            layer.msg('登录失败！');
                                        }
                                    }
                                });
                                /*document.getElementById("form1").submit();*/
                                /*into();//验证成功，登录验证*/
                            }else{
                                layer.msg("验证失败，请重新验证！");
                                // alert("验证失败，请重新验证！");
                                console.log("33");
                            }
                        }
                    });
                }else if(res.ret===2){
                    layer.msg("验证已关闭，验证成功才能登录系统！");
                    // alert("验证已关闭，验证成功才能登录系统！");
                    console.log("44");
                }
            });
            captcha1.show();
            /*$.ajax({
                url:'/login_end',
                type:'POST',
                data:data,
                success: function(result){
                    if(result.code==200){
                        layer.msg("登录成功！");
                    }else{
                        layer.msg("失败成功！");
                    }
                }
            })*/

            /*layer.msg('登录成功', function () {

            });*/
            return false;
        });
    });

    /*function subForm(){
        var checkUserName = document.getElementById("username").value;
        var checkPassword = document.getElementById("password").value;

        if(checkUserName === ''){

        }else if(checkPassword === ''){

        }else{
            var captcha1 = new TencentCaptcha('2038374610', function(res) {
                console.log(res);
                if(res.ret === 0){
                    console.log(res.ret);
                    $.ajax({
                        url: "/checkLogin",
                        type: "POST",
                        data:{
                            "ticket":res.ticket,
                            "randstr":res.randstr
                        },
                        success: function (data) {
                            console.log("11");
                            if (data.result ===1) {
                                /!*document.getElementById("form1").submit();*!/
                                console.log("22");
                                into();//验证成功，登录验证
                            }else{
                                alert("验证失败，请重新验证！");
                                console.log("33");
                            }
                        }
                    })
                }else if(res.ret===2){
                    alert("验证已关闭，验证成功才能登录系统！");
                    console.log("44");
                }
            });
            captcha1.show();
        }
    }
    function into() {
        $('#form1').submit();
        //提交登录表单
    }*/

</script>
</body>
</html>